import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import Iview from "iview";
import i18n from "@/locale";
import config from "@/config";
import "iview/dist/styles/iview.css";
import echarts from "echarts";
import echart from "@/libs/echarts";
import login from "@/api/login";

Vue.config.productionTip = false;
Vue.use(Iview, {
  i18n: (key, value) => i18n.t(key, value)
});

Vue.use(echart);

/**
 * @description 全局注册应用配置
 */
Vue.prototype.$config = config;

Vue.prototype.$echarts = echarts;

Vue.prototype.$login = login;

// 通过读取components文件夹下的文件引入组件,不在需要每个都去import一遍,再去注册了;
/* 参数: 文件路径,是否遍历子目录,正则表达式匹配文件类型 */
const requireComponent = require.context("@/components/", true, /\.vue$/);
/*遍历文件名,并注册*/
requireComponent.keys().forEach(fileName => {
  const componentConfig = requireComponent(fileName);
  let name = fileName.split("/");
  let componentName = name[name.length - 1].replace(".vue", "");
  Vue.component(componentName, componentConfig.default || componentConfig);
});

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount("#app");
